package com.lcj.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcj.commonutils.R;
import com.lcj.eduService.entity.EduCourse;
import com.lcj.eduService.entity.EduTeacher;
import com.lcj.eduService.service.EduCourseService;
import com.lcj.eduService.service.EduTeacherService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author：LCJ
 * @Description：
 * @Date：Create in 19:24 2021/3/24 0024
 */
@RestController
@RequestMapping("eduService/teacherFront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService courseService;
    //分页查询
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,
                                 @PathVariable long limit){
        Page<EduTeacher> teacherPage =new Page<>(page,limit);
        Map<String,Object> data = eduTeacherService.getTeacherFrontList(teacherPage);
        return R.ok().data(data);
    }


    //根据id查询讲师信息
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        EduTeacher teacher = eduTeacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
